package net.yebaihe.wc;

import java.util.HashMap;

import net.yebaihe.wc.DataMan.MSGTYPE;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Register extends StateMachine{

	private EditText edtEmail;
	private EditText edtPasswd;
	private EditText edtUsername;

	@Override
	protected void prepareClient(View client) {
		edtEmail=(EditText) client.findViewById(R.id.edtEmail);
		edtUsername=(EditText) client.findViewById(R.id.edtUsername);
		edtPasswd=(EditText) client.findViewById(R.id.edtPasswd);
		Button btnRegister=(Button) client.findViewById(R.id.btnRegister);
		btnRegister.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View arg0) {
				if (edtEmail.getText().toString().length()<=0){
					Toast.makeText(Register.this, "请输入正确的邮件地址！", Toast.LENGTH_LONG).show();
					return;
				}
				DataMan.get(Register.this).register(edtEmail.getText().toString(),
						edtUsername.getText().toString(),
						edtPasswd.getText().toString());
			}
		});
	}

	@Override
	protected int getLayoutRes() {
		return R.layout.register;
	}

	@Override
	protected String getTopbarTitle() {
		return "注册";
	}

	@Override
	protected void HandleMessage(MSGTYPE msgtype, boolean ret,
			HashMap<String, String> params) {
		switch (msgtype){
		case REGISTER:
			if (ret){
				Toast.makeText(this, "注册成功!", Toast.LENGTH_LONG).show();
			}
			else{
				Toast.makeText(this, "注册失败!", Toast.LENGTH_LONG).show();
			}
			break;
		}
	}

}
